/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gidoo.xmldb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author thomas
 */
public class ConnectionHelper
{

  /** Connects to a standard network Derby database (localhost) */
  public static Connection connect2DB(String dbname, boolean create)
  {
    Connection result = null;
    try
    {
      Class.forName("org.apache.derby.jdbc.ClientDriver");
    }
    catch(ClassNotFoundException ex)
    {
      Logger.getLogger(ConnectionHelper.class.getName()).log(Level.SEVERE, null, ex);
      return null;
    }
    try
    {
      result = DriverManager.getConnection("jdbc:derby://localhost/" + dbname +
        (create ? ";create=true" : ""));
    }
    catch(SQLException ex)
    {
      Logger.getLogger(ConnectionHelper.class.getName()).log(Level.SEVERE, null, ex);
    }

    return result;
  }
}
